package com.cndw.kungfu.model.goods.domain;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.cndw.kungfu.config.ConstantsConfig;
import com.cndw.kungfu.domain.GoodsMode;
import com.cndw.kungfu.ext.XmlProcesser;
import com.cndw.kungfu.model.Context;
import com.cndw.kungfu.vo.goodsvo.GoodsVO;

public class HeroShop {
	private int id;

	private int type;

	private int goodsId;

	private int cost;

	private int costId;

	private GoodsVO goodsVO;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public int getGoodsId() {
		return goodsId;
	}

	public void setGoodsId(int goodsId) {
		this.goodsId = goodsId;
	}

	public int getCost() {
		return cost;
	}

	public void setCost(int cost) {
		this.cost = cost;
	}

	public int getCostId() {
		return costId;
	}

	public void setCostId(int costId) {
		this.costId = costId;
	}

	public GoodsVO getGoodsVO() {
		return goodsVO;
	}

	public void setGoodsVO(GoodsVO goodsVO) {
		this.goodsVO = goodsVO;
	}

	private static final Map<Integer, HeroShop> dataMap = new HashMap<Integer, HeroShop>();

	private static final String configFile = "heroShop.xml";

	static {
		load();
	}

	public static synchronized void load() {
		if (dataMap.isEmpty()) {
			String fileName = ConstantsConfig.getLocaleResource() + configFile;
			List<HeroShop> dataList = XmlProcesser.processXml(HeroShop.class, fileName);
			if (dataList != null && dataList.size() > 0) {
				for (HeroShop e : dataList) {
					GoodsMode goodsMode = Context.getGoodsServer().getModeById(e.getGoodsId());
					if (goodsMode == null) {
						continue;
					}
					e.setGoodsVO(goodsMode.toGoodsVO());
					dataMap.put(e.getId(), e);
				}
			}
		}
	}

	public static synchronized void clear() {
		dataMap.clear();
		load();
	}

	public static Collection<HeroShop> getAll() {
		return dataMap.values();
	}

	public static HeroShop getOne(int id) {
		return dataMap.get(id);
	}

}
